package com.ruicar.afs.cloud.manage.creditchange.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.util.EmptyUtils;
import com.ruicar.afs.cloud.manage.common.entity.ManageRepaymentDateChange;
import com.ruicar.afs.cloud.manage.common.service.ManageRepaymentDateChangeService;
import com.ruicar.afs.cloud.manage.creditchange.condition.CustInfoChangeCondition;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author chuke
 * @create 2020/7/4 13:56
 * 还款日变更
 */
@Slf4j
@RestController
@RequestMapping("/repaymentChange")
@AllArgsConstructor
public class RepaymentDateController {
    private final ManageRepaymentDateChangeService repaymentDateChangeService;
    private final ManageRepaymentDateChangeService dateChangeService;

    @ApiOperation(value = "已做还款日变更的案件列表")
    @PostMapping("/getManageRepaymentChangeList")
    public IResponse getManageBankCardChangeContractNo (@RequestBody CustInfoChangeCondition condition){

           return new IResponse().setData(repaymentDateChangeService.page(new Page(condition.getPageNumber(),condition.getPageSize())
                , Wrappers.<ManageRepaymentDateChange>query().lambda()
                           .like(EmptyUtils.isNotEmpty(condition.getDataSource()),ManageRepaymentDateChange::getDataSource,condition.getDataSource())
                           .like(EmptyUtils.isNotEmpty(condition.getProcessStatus()),ManageRepaymentDateChange::getProcessStatus,condition.getProcessStatus())
                           .like(StringUtils.isNotEmpty(condition.getContractNo()),ManageRepaymentDateChange::getContractNo,condition.getContractNo())
                           .like(StringUtils.isNotEmpty(condition.getApplyNo()),ManageRepaymentDateChange::getApplyNo,condition.getApplyNo())
                           .like(StringUtils.isNotEmpty(condition.getCustName()),ManageRepaymentDateChange::getCustName,condition.getCustName())
                           .ge(EmptyUtils.isNotEmpty(condition.getStartCreateDate()),ManageRepaymentDateChange::getCreateTime,condition.getStartCreateDate())
                           .le(EmptyUtils.isNotEmpty(condition.getEndCreateDate()),ManageRepaymentDateChange::getCreateTime,condition.getEndCreateDate())
                           .ge(EmptyUtils.isNotEmpty(condition.getStartFinishDate()),ManageRepaymentDateChange::getEndDate,condition.getStartFinishDate())
                           .le(EmptyUtils.isNotEmpty(condition.getEndFinishDate()),ManageRepaymentDateChange::getEndDate,condition.getEndFinishDate())
                           .eq(EmptyUtils.isNotEmpty(condition.getChannelId()),ManageRepaymentDateChange::getChannelId,condition.getChannelId())));
    }

    @ApiOperation(value = "还款日信息变更")
    @PostMapping("/submitChange")
    public IResponse submitChange (@RequestBody ManageRepaymentDateChange change){
        repaymentDateChangeService.submitChange(change);
        return new IResponse().setData(change);
    }

    @ApiOperation(value = "查询还款日变更表中记录")
    @PostMapping("/findPoundageByContractNo")
    public IResponse findPoundageByContractNo(@RequestParam(value = "contractNo") String contractNo,@RequestParam(value = "caseNo",required = false) String caseNo){
        List<ManageRepaymentDateChange> change = dateChangeService.list(Wrappers.<ManageRepaymentDateChange>lambdaQuery()
                .eq(ManageRepaymentDateChange::getContractNo, contractNo)
                .eq(EmptyUtils.isNotEmpty(caseNo),ManageRepaymentDateChange::getCaseNo, caseNo));
        return new IResponse().setData(change);
    }
}
